import axios from 'axios'
import store from '@/store'
import JSONBig from 'json-bigint'
const abc = '{"art_id":1323622365027893248}'
console.log(JSON.parse(abc))
console.log(JSONBig.parse(abc))
console.log(JSONBig.parse(abc).art_id + '')

const request = axios.create({
  // baseURL: 'http://ttapi.research.itcast.cn/'
  baseURL: 'http://toutiao-app.itheima.net/',
  // transformResponse 允许自定义原始的响应数据（字符串
  transformResponse: [function (data) {
    try {
      return JSONBig.parse(data)
    } catch (err) {
      return { data }
    }
  }]

})

request.interceptors.request.use(config => {
  const { user } = store.state
  if (user && user.token) {
    config.headers.Authorization = 'Bearer ' + user.token
  }
  // console.log(config)
  return config
})

export default request
